<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body></body>
  <script>
    // 浅拷贝
    let user = { name: "小灰" };
    let cms = { name: user.name };
    console.log(cms);
    cms.name = "小美";
    console.log(user);

    // 使用forIn循环
    let car = { price: 10000, wheel: 4 };
    let obj = {};
    for (const key in car) {
      obj[key] = car[key];
    }
    console.log(obj);

    // 使用assign
    let obj_one = Object.assign({}, car);
    console.log(obj_one);

    // 使用展开语法
    let obj_two = { ...car };
    console.log(obj_two);
    // 以上四种方法的基本思想就是创建一个新的对象，然后再把待拷贝的对象属性复制过来
  </script>
</html>
